package org.ceva.training.ui.renderer;

import java.util.Comparator;
import java.util.List;

import org.ceva.training.persistence.bo.User;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

public class SelectListBoxRenderer<T> implements ListitemRenderer {

	private List<T> selectedObjectList;
	
	private Comparator<T> comparator;
	
	public SelectListBoxRenderer(List<T> users,Comparator<T> comparator) {
		super();
		this.selectedObjectList = users;
		this.comparator=comparator;
	}


	public void render(Listitem item, Object data) throws Exception {
		
		if(selectedObjectList!=null)
		{
			for (T selectedObj : selectedObjectList) {
				if(selectedObj!=null && comparator.compare(selectedObj,(T)data)==0)
				{
					item.setSelected(true);
				}
			}
		}
		
		item.setLabel(data.toString());
		item.setValue(data);
		
	}

}
